/**
 * 自定义插件  匹配不同设计稿
 */
import type { Plugin } from "postcss";

interface Options {
    viewportWidth?: number,
}
const defaultOptions: Options = {
    viewportWidth: 1920,
    // viewportWidth: 375,
}
export const postcssPxToViewport = (options: Options = defaultOptions): Plugin => {
    const opt = Object.assign({}, defaultOptions, options);
    return {
        postcssPlugin: 'postcss-px-to-viewport',
        Declaration(node) {
            // console.log(node.prop, node.value);//查看当前属性
            // if (node.value.includes('px')) {  //除px外，还可以转换任何的值，比如em等
            //     const num = parseFloat(node.value);
            //     node.value = `${((num / opt.viewportWidth!) * 100).toFixed(2)}vw`;//设计稿为375
            // }
        }
    }
}